/** 
 * 文 件 名:RecordManageLogic.java
 * Copyright (C) 2007-2012:杭州希禾信息技术有限公司 版权所有 
 * 创 建 人:林洪波
 * 日    期:2012-3-12 下午3:36:17
 * 修 改 人: 
 * 日   期:
 * 修改描述:
 * 描   述:TODO
 */
package net.seehealth.healthpad.business.recordmanage;

import java.io.InputStream;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import net.seehealth.healthpad.application.base.BaseLogic;
import net.seehealth.healthpad.application.base.BaseModel;
import net.seehealth.healthpad.application.base.HealthApplicationContext;
import net.seehealth.healthpad.application.network.WebServiceManager;
import net.seehealth.healthpad.application.template.OneRecorder;
import net.seehealth.healthpad.application.template.TwoRecorder;
import net.seehealth.healthpad.application.util.DataServiceHelper;
import net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic;
import net.seehealth.healthpad.model.healthmanage.ChineseMedicineAssement;
import net.seehealth.healthpad.model.healthmanage.DepartmentModel;
import net.seehealth.healthpad.model.healthmanage.ElectronicMedicalRecordModel;
import net.seehealth.healthpad.model.healthmanage.HealthAbnor;
import net.seehealth.healthpad.model.healthmanage.HealthReportModel;
import net.seehealth.healthpad.model.healthmanage.MainParam;
import net.seehealth.healthpad.model.healthmanage.ModeldetailModel;
import net.seehealth.healthpad.model.healthmanage.ModelevalModel;
import net.seehealth.healthpad.model.healthmanage.PharmacyRecordModel;
import net.seehealth.healthpad.model.healthmanage.PsychologicalAssessmentModel;
import net.seehealth.healthpad.model.healthmanage.RecordItemModel;

/**
 * @className RecordManageLogic
 * @author 林洪波
 * @description TODO
 * @date 2012-3-12 下午5:22:54
 */
public class RecordManageLogic extends BaseLogic implements IRecordManageLogic {

	/**
	 * @param application
	 */
	public RecordManageLogic(HealthApplicationContext application) {
		super(application);
	}

	private abstract class ParseHandler<T> {

		public List<T> getResult() {
			return result;
		}

		protected List<T> result;

		private XmlPullParser parse;

		private void init() throws XmlPullParserException {
			XmlPullParserFactory xmlFactory = XmlPullParserFactory
					.newInstance();
			parse = xmlFactory.newPullParser();
			result = new ArrayList<T>();
		}

		public ParseHandler(InputStream datasouce) throws Exception {
			init();
			parse.setInput(datasouce, "utf-8");
			parse(parse, result);
		}

		public ParseHandler(String datasouce) throws Exception {
			init();
			parse.setInput(new StringReader(datasouce));
			parse(parse, result);
		}

		public abstract void parse(XmlPullParser parse, List<T> result)
				throws Exception;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic
	 * #queryAllHealthReportModel(int)
	 */
	
	public List<HealthReportModel> queryNewHealthReportAndOtherReportDetailFromWeb(int userinfo_famialy_pk)
			throws Exception {
		InputStream dataSouce = null;

		ParseHandler<HealthReportModel> parse = new ParseHandler<HealthReportModel>(
				dataSouce) {

			@Override
			public void parse(XmlPullParser parse,
					List<HealthReportModel> result) throws Exception {
				List<HealthReportModel> reportList = null;
				HealthReportModel healthReport = null;
				List<DepartmentModel> departments = null;
				DepartmentModel department = null;
				RecordItemModel recordItem = null;
				List<RecordItemModel> recordItems = null;
				HealthAbnor healthAbnor = null;
				List<HealthAbnor> healthAbnors = null;
				int eventType = parse.getEventType();
				outter: while (eventType != XmlPullParser.END_DOCUMENT) {
					switch (eventType) {
					case XmlPullParser.START_TAG:
						String tagName = parse.getName().trim();
						if ("isOrNo".equalsIgnoreCase(tagName)) {
							// 无数据
							if (!"1".equalsIgnoreCase(parse.nextText().trim())) {
								break outter;
							}
						} else if ("HealthReportList".equalsIgnoreCase(tagName)) {
							reportList = new ArrayList<HealthReportModel>();
						} else if ("HealthReport".equalsIgnoreCase(tagName)) {
							healthReport = new HealthReportModel();
							// 综合平台体检报告id
							healthReport
									.setReport_id(Integer.parseInt(parse
											.getAttributeValue(null,
													"healthReportId")));
							// 体检时间
							healthReport.setRecordTime(parse.getAttributeValue(
									null, "date"));
							// 体检机构
							healthReport.setRecord_address(parse
									.getAttributeValue(null, "address"));
							//版本号
							healthReport.setVersion(Integer.parseInt(parse.getAttributeValue(null,"version")));
							
							
						} else if ("DepartMentList".equalsIgnoreCase(tagName)) {
							// 体检科室
							departments = new ArrayList<DepartmentModel>();
						} else if ("DepartMent".equalsIgnoreCase(tagName)) {
							department = new DepartmentModel();
							// 综合平台科室id
							department.setDepartmentId(Integer.parseInt(parse
									.getAttributeValue(null, "departmentId")));
							// 科室名称
							department.setDepartmentName(parse
									.getAttributeValue(null, "departMentName"));
						} else if ("RecordItemList".equalsIgnoreCase(tagName)) {
							recordItems = new ArrayList<RecordItemModel>();
						} else if ("RecordItem".equalsIgnoreCase(tagName)) {
							recordItem = new RecordItemModel();
							// 体检小项id
							recordItem.setItemId(Integer.parseInt(parse
									.getAttributeValue(null, "recordItemid")));
						} else if ("ItemName".equalsIgnoreCase(tagName)) {
							recordItem.setItemName(parse.nextText().trim());
						} else if ("ItemType".equalsIgnoreCase(tagName)) {
							recordItem.setItemType(parse.nextText().trim());
						} else if ("Unit".equalsIgnoreCase(tagName)) {
							recordItem.setUnit(parse.nextText().trim());
						} else if ("ItemInterpretation"
								.equalsIgnoreCase(tagName)) {
							recordItem.setItemInterpretation(parse.nextText()
									.trim());
						} else if ("ItemResult".equalsIgnoreCase(tagName)) {
							recordItem.setItemResult(parse.nextText().trim());
						} else if ("AbnorList".equalsIgnoreCase(tagName)) {
							healthAbnors = new ArrayList<HealthAbnor>();
						} else if ("Abnor".equalsIgnoreCase(tagName)) {
							healthAbnor = new HealthAbnor();
							healthAbnor.setHealthAbnorID(Integer.parseInt(parse
									.getAttributeValue(null, "abnorId")));
						} else if ("AbnorName".equalsIgnoreCase(tagName)) {
							healthAbnor.setAbnorName(parse.nextText().trim());
						} else if ("MedicineExplain".equalsIgnoreCase(tagName)) {
							healthAbnor.setMedicineExplain(parse.nextText()
									.trim());
						} else if ("Advise".equalsIgnoreCase(tagName)) {
							healthAbnor.setAdvice(parse.nextText().trim());
						} else if ("CommonCause".equalsIgnoreCase(tagName)) {
							healthAbnor.setCommonCause(parse.nextText().trim());
						}
						break;
					case XmlPullParser.END_TAG:
						String endtagName = parse.getName().trim();
						if ("RecordItem".equalsIgnoreCase(endtagName)) {
							recordItems.add(recordItem);
							recordItem = null;
						} else if ("RecordItemList"
								.equalsIgnoreCase(endtagName)) {
							department.setRecordItems(recordItems);
							recordItems = null;
						} else if ("DepartMent".equalsIgnoreCase(endtagName)) {
							departments.add(department);
							department = null;
						} else if ("DepartMentList"
								.equalsIgnoreCase(endtagName)) {
							healthReport.setDepartments(departments);
							departments = null;
						} else if ("Abnor".equalsIgnoreCase(endtagName)) {
							healthAbnors.add(healthAbnor);
							healthAbnor = null;
						} else if ("AbnorList".equalsIgnoreCase(endtagName)) {
							healthReport.setHealthAbnors(healthAbnors);
							healthAbnors = null;
						} else if ("HealthReport".equalsIgnoreCase(endtagName)) {
							reportList.add(healthReport);
							healthReport = null;
						} else if ("HealthReportList"
								.equalsIgnoreCase(endtagName)) {
							result.addAll(reportList);
						}
						break;
					default:
						break;
					}
					eventType = parse.next();
				}
			}

		};
		List<HealthReportModel> result = parse.getResult();

		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * net.seehealth.healthpad.application.base.BaseLogic#queryDataByUserId(int)
	 */
	@Override
	public BaseModel queryDataByUserId(int userId) {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * net.seehealth.healthpad.application.base.BaseLogic#queryDataById(int)
	 */
	@Override
	public BaseModel queryDataById(int pk) {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * net.seehealth.healthpad.application.base.BaseLogic#addData(net.seehealth
	 * .healthpad.application.base.BaseModel)
	 */
	@Override
	public boolean addData(BaseModel model) {
		// TODO Auto-generated method stub
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * net.seehealth.healthpad.application.base.BaseLogic#modifData(net.seehealth
	 * .healthpad.application.base.BaseModel)
	 */
	@Override
	public boolean modifData(BaseModel model) {
		// TODO Auto-generated method stub
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * net.seehealth.healthpad.application.base.BaseLogic#modifData(java.util
	 * .ArrayList)
	 */
	@Override
	public boolean modifData(ArrayList<BaseModel> datas) {
		// TODO Auto-generated method stub
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic
	 * #queryNewModeldetail(int)
	 */
	@Override
	public List<ModeldetailModel> queryNewModeldetailFromWeb(final int userId)
			throws Exception {
		// TODO Auto-generated method stub
		String requestSoap=DataServiceHelper.genSimpleSoapContent("GetModelDetailList","userID",String.valueOf(userId));
		String dataSouce=WebServiceManager.getResponseSoapBodyString(requestSoap,WebServiceManager.URL) ;
		
		ParseHandler<ModeldetailModel> parse = new ParseHandler<ModeldetailModel>(
				dataSouce) {

			@Override
			public void parse(XmlPullParser parse, List<ModeldetailModel> result)
					throws Exception {
				ModeldetailModel modeldetail=null;
				List<ModeldetailModel> modeldetails=null;
				HashMap<String,String> defends=null;
				List<MainParam> mainParams=null;
				MainParam mainParam=null;
				String key=null;
				String value=null;
				int hasTitleAndContent=0;
				int eventType = parse.getEventType();
				outter: while (eventType != XmlPullParser.END_DOCUMENT) {
					switch (eventType) {
					case XmlPullParser.START_TAG:
						String tagName = parse.getName().trim();
						if ("isOrNo".equalsIgnoreCase(tagName)) {
							// 无数据
							if (!"1".equalsIgnoreCase(parse.nextText().trim())) {
								break outter;
							}
						}
						else if("ModelDetailList".equalsIgnoreCase(tagName))
						{
							if(modeldetails==null)
							{
								modeldetails=new ArrayList<ModeldetailModel>();
							}
						}
						else if("ModelDetail".equalsIgnoreCase(tagName))
						{
							if(modeldetail==null)
							{
								modeldetail=new ModeldetailModel();
								modeldetail.setUserInfoId(userId);
							}
						}
						else if("ModelID".equalsIgnoreCase(tagName))
						{
							Integer modelId=Integer.parseInt(parse.nextText().trim());
							ModelevalModel modeleval=getModelEvalByModelId(modelId);
							modeldetail.setModeleval(modeleval);
							modeldetail.setModelevalId(modeleval==null?0:modeleval.getId());
						}
						else if("RiskLevel".equalsIgnoreCase(tagName))
						{
							String risklevel=parse.nextText().trim();
							modeldetail.setRISKLEVEL(risklevel);
						}
						else if("CurrentValue".equalsIgnoreCase(tagName))
						{
							float currentValue=Float.parseFloat(parse.nextText().trim());
							modeldetail.setCurrentValue(currentValue);
						}
						else if("TargetValue".equalsIgnoreCase(tagName))
						{
							float targetValue=Float.parseFloat(parse.nextText().trim());
							modeldetail.setTargetvalue(targetValue);
						}
						else if("IdealValue".equalsIgnoreCase(tagName))
						{
							float idealValue=Float.parseFloat(parse.nextText().trim());
							modeldetail.setIdealvalue(idealValue);
						}
						else if("Memo".equalsIgnoreCase(tagName))
						{
							String memo=parse.nextText().trim();
							modeldetail.setMemo(memo);
						}
						else if("RiskDefendList".equalsIgnoreCase(tagName))
						{
							if(defends==null)
							{
								defends=new HashMap<String, String>();
							}
						}
						else if("Title".equalsIgnoreCase(tagName))
						{
							key=parse.nextText().trim();
							hasTitleAndContent++;
						}
						else if("Content".equalsIgnoreCase(tagName))
						{
							value=parse.nextText().trim();
							hasTitleAndContent++;
						}
						else if("MainItemList".equalsIgnoreCase(tagName))
						{
							if(mainParams==null)
							{
								mainParams=new ArrayList<MainParam>();
							}
						}
						else if("Item".equalsIgnoreCase(tagName))
						{
							if(mainParam==null)
							{
								mainParam=new MainParam();
							}
						}
						else if("ParamName".equalsIgnoreCase(tagName))
						{
							mainParam.setParamName(parse.nextText().trim());
						}
						else if("Result".equalsIgnoreCase(tagName))
						{
							mainParam.setResult(parse.nextText().trim());
						}
						else if("CommonRef".equalsIgnoreCase(tagName))
						{
							mainParam.setCommonRef(parse.nextText().trim());
						}
						else if("Warn".equalsIgnoreCase(tagName))
						{
							mainParam.setWarn(parse.nextText().trim());
						}
						break;
					case XmlPullParser.END_TAG:
						String endTage=parse.getName().trim();
						if("RiskDefend".equalsIgnoreCase(endTage))
						{
							if(defends!=null&&hasTitleAndContent==2)
							{
								defends.put(key, value);
								hasTitleAndContent=0;
								key=null;
								value=null;
							}
						}
						else if("RiskDefendList".equalsIgnoreCase(endTage))
						{
							if(modeldetail!=null)
							{
								modeldetail.setRiskdefend(defends);
								defends=null;
							}
						}
						else if("Item".equalsIgnoreCase(endTage))
						{
							if(mainParams!=null)
							{
								mainParams.add(mainParam);
							}
							mainParam=null;
						}
						else if("MainItemList".equalsIgnoreCase(endTage))
						{
							if(modeldetail!=null)
							{
								modeldetail.setMainParams(mainParams);
							}
							mainParams=null;
						}
						else if("ModelDetail".equalsIgnoreCase(endTage))
						{
							if(modeldetails!=null&&modeldetail!=null)
							{
								modeldetails.add(modeldetail);
							}
							modeldetail=null;
						}
						else if("ModelDetailList".equalsIgnoreCase(endTage))
						{
							result.addAll(modeldetails);
						}
						break;
						default:
							break;
					}
					eventType = parse.next();
				}
			}
		};
		List<ModeldetailModel> result = parse.getResult();
		
		return result;
	}


	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryHealthAbnorByIdFromLocal(int)
	 */
	@Override
	public HealthAbnor queryHealthAbnorByIdFromLocal(int abnorId)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryRecordItemCompareByIdFromWeb(int)
	 */
	@Override
	public List<TwoRecorder<HealthReportModel, RecordItemModel>> queryRecordItemCompareByIdFromWeb(
			int itemId) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryHealthReportCompareByIdsFromWeb(java.lang.Integer[])
	 */
	@Override
	public List<TwoRecorder<HealthReportModel, List<DepartmentModel>>> queryHealthReportCompareByIdsFromWeb(
			Integer[] ids) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryALLMedicalRecordFromWeb(int)
	 */
	@Override
	public List<ElectronicMedicalRecordModel> queryALLMedicalRecordFromWeb(
			int famialyPrimaryKey) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryByIdFromLocal(int)
	 */
	@Override
	public ElectronicMedicalRecordModel queryByIdFromLocal(int primaryKey)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#addElectronicMedicalRecordToWeb(net.seehealth.healthpad.model.healthmanage.ElectronicMedicalRecordModel)
	 */
	@Override
	public int addElectronicMedicalRecordToWeb(
			ElectronicMedicalRecordModel ElectronicMedical) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#addElectronicMedicalRecordToLocal(net.seehealth.healthpad.model.healthmanage.ElectronicMedicalRecordModel)
	 */
	@Override
	public int addElectronicMedicalRecordToLocal(
			ElectronicMedicalRecordModel ElectronicMedical) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#modifElectronicMedicalToWeb(net.seehealth.healthpad.model.healthmanage.ElectronicMedicalRecordModel)
	 */
	@Override
	public boolean modifElectronicMedicalToWeb(
			ElectronicMedicalRecordModel ElectronicMedical) throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#modifElectronicMedicalToLoacl(net.seehealth.healthpad.model.healthmanage.ElectronicMedicalRecordModel)
	 */
	@Override
	public boolean modifElectronicMedicalToLoacl(
			ElectronicMedicalRecordModel ElectronicMedical) throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryHealthAbnorByIdFromWeb(int)
	 */
	@Override
	public HealthAbnor queryHealthAbnorByIdFromWeb(int abnorId)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#addPharmacyRecordModelToWeb(net.seehealth.healthpad.model.healthmanage.PharmacyRecordModel)
	 */
	@Override
	public int addPharmacyRecordModelToWeb(PharmacyRecordModel pharmacyRecord)
			throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#addPharmacyRecordModelToLocal(net.seehealth.healthpad.model.healthmanage.PharmacyRecordModel)
	 */
	@Override
	public int addPharmacyRecordModelToLocal(PharmacyRecordModel pharmacyRecord)
			throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#modifPharmacyRecordModelToWeb(net.seehealth.healthpad.model.healthmanage.PharmacyRecordModel)
	 */
	@Override
	public boolean modifPharmacyRecordModelToWeb(
			PharmacyRecordModel pharmacyRecord) throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#modifPharmacyRecordModelToLocal(net.seehealth.healthpad.model.healthmanage.PharmacyRecordModel)
	 */
	@Override
	public boolean modifPharmacyRecordModelToLocal(
			PharmacyRecordModel pharmacyRecord) throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryPharmacyRecordByIdFromWeb(int)
	 */
	@Override
	public PharmacyRecordModel queryPharmacyRecordByIdFromWeb(
			int pharmacyPrimayKey) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryPharmacyRecordByIdFromLocal(int)
	 */
	@Override
	public PharmacyRecordModel queryPharmacyRecordByIdFromLocal(
			int pharmacyPrimayKey) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryALLModelDetailCompareFromWeb(int)
	 */
	@Override
	public List<OneRecorder<List<ModeldetailModel>>> queryALLModelDetailCompareFromWeb(
			int userId) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#querySingleModelDetailCompareByModelIdFromWeb(int, int)
	 */
	@Override
	public List<ModeldetailModel> querySingleModelDetailCompareByModelIdFromWeb(
			int userId, int modelId) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryTwoPsyFromWeb(int)
	 */
	@Override
	public TwoRecorder<PsychologicalAssessmentModel, PsychologicalAssessmentModel> queryTwoPsyFromWeb(
			int userId) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryTwoPsyFromLocal(int)
	 */
	@Override
	public TwoRecorder<PsychologicalAssessmentModel, PsychologicalAssessmentModel> queryTwoPsyFromLocal(
			int userId) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryTwoChiFromWeb(int)
	 */
	@Override
	public TwoRecorder<ChineseMedicineAssement, ChineseMedicineAssement> queryTwoChiFromWeb(
			int userId) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryTwoChiFromLocal(int)
	 */
	@Override
	public TwoRecorder<ChineseMedicineAssement, ChineseMedicineAssement> queryTwoChiFromLocal(
			int userId) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	private ModelevalModel getModelEvalByModelId(int modelId)
	{
		ModelevalModel modeeval=null;
		SQLiteDatabase database=this.healthSqliteHelper.getReadableDatabase();
		String sql="select ID,MODEL_NAME,DESCRIPTION,MODEL_ID from MODELEVAL where MODEL_ID=?";
		Cursor cursor=database.rawQuery(sql,new String[]{String.valueOf(modelId)});
		if(cursor.moveToFirst())
		{
			modeeval=new ModelevalModel();
			modeeval.setId(cursor.getInt(cursor.getColumnIndex("ID")));
			modeeval.setModelId(cursor.getInt(cursor.getColumnIndex("ID")));
			modeeval.setDescription(cursor.getString(cursor.getColumnIndex("DESCRIPTION")));
			modeeval.setModelName(cursor.getString(cursor.getColumnIndex("MODEL_NAME")));
			modeeval.setModelId(modelId);
			
		}
		cursor.close();
		return modeeval;
	}

	
	public boolean addNewModelDetailToLocal(List<ModeldetailModel> modelDetails) throws Exception
	{
		
		SQLiteDatabase database=null;
		boolean flag=true;
		try
		{
			database=this.healthSqliteHelper.getWritableDatabase();
			database.beginTransaction();
			
			
			
			
			
			//删除主要参数
			database.execSQL("delete from MainParam");
			//执行删除主要评估详情
			database.execSQL("delete from MODELDETAIL");
			
			for(ModeldetailModel modelDetail:modelDetails)
			{

			//添加数据
			ContentValues contentValue=new ContentValues();
			contentValue.put("RISKLEVEL", modelDetail.getRISKLEVEL());
			contentValue.put("CURRENTVALUE", modelDetail.getCurrentValue());
			contentValue.put("TARGETVALUE", modelDetail.getTargetvalue());
			contentValue.put("IDEALVALUE", modelDetail.getIdealvalue());
			contentValue.put("MEMO", modelDetail.getMemo());
			contentValue.put("MODELEVAL_ID", modelDetail.getModelevalId());
			contentValue.put("USERINFO_ID", modelDetail.getUserInfoId());
			String defend="";
			for(Entry<String,String> entry:modelDetail.getRiskdefend().entrySet())
			{
				defend+=entry.getKey()+"|"+entry.getValue()+"*";
			}
			if(defend.length()>0)
			{
				defend=defend.substring(0,defend.length()-1);
			}
			contentValue.put("RISKDEFEND", defend);
			contentValue.put("DATE",modelDetail.getDate());
			long pk=database.insert("MODELDETAIL",null, contentValue);
			modelDetail.setId((int)pk);
			for(MainParam mainParam :modelDetail.getMainParams())
			{
				ContentValues itemValue=new ContentValues();
				itemValue.put("PARAM_NAME",mainParam.getParamName());
				itemValue.put("RESULT",mainParam.getResult());
				itemValue.put("COMMONREF",mainParam.getCommonRef());
				itemValue.put("WARN",mainParam.getWarn());
				itemValue.put("MODELDETAIL_ID",(int)pk);
				int spk=(int)database.insert("MainParam",null,itemValue);
				mainParam.setId(spk);
				mainParam.setModeldetailId((int)pk);
			}
		   }
		   database.setTransactionSuccessful();
		}
		catch(Exception exception)
		{
			exception.printStackTrace();
			flag=false;
		}
		finally
		{
			database.endTransaction();
		}
		return flag;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryNewModelDetailFromLocal(int)
	 */
	@Override
	public List<ModeldetailModel> queryNewModelDetailFromLocal(
			int userinfo_famialy_pk) throws Exception {
		// TODO Auto-generated method stub
		SQLiteDatabase database=null;
		
		List<ModeldetailModel> modelDetails=null;
		
		try
		{
			database=this.healthSqliteHelper.getReadableDatabase();
			
			Cursor cursor=database.rawQuery("select ID,RISKLEVEL,CURRENTVALUE,TARGETVALUE," +
					"IDEALVALUE,MEMO,MODELEVAL_ID,RISKDEFEND,DATE,USERINFO_ID from MODELDETAIL where USERINFO_ID =?",
					new String[]{String.valueOf(userinfo_famialy_pk)});
			if(cursor!=null&&cursor.getCount()>0)
			{
				modelDetails=new ArrayList<ModeldetailModel>();
				while(cursor.moveToNext())
				{
					ModeldetailModel modelDetail=new ModeldetailModel();
					modelDetail.setId(cursor.getInt(cursor.getColumnIndex("ID")));
					modelDetail.setRISKLEVEL(cursor.getString(cursor.getColumnIndex("RISKLEVEL")));
					modelDetail.setTargetvalue(cursor.getFloat(cursor.getColumnIndex("CURRENTVALUE")));
					modelDetail.setIdealvalue(cursor.getFloat(cursor.getColumnIndex("IDEALVALUE")));
					modelDetail.setCurrentValue(cursor.getFloat(cursor.getColumnIndex("CURRENTVALUE")));
					modelDetail.setMemo(cursor.getString(cursor.getColumnIndex("MEMO")));
					modelDetail.setModelevalId(cursor.getInt(cursor.getColumnIndex("MODELEVAL_ID")));
					Map<String,String> defends=new HashMap<String,String>();
					String dataDefends=cursor.getString(cursor.getColumnIndex("RISKDEFEND"));
					if(dataDefends!=null&&dataDefends.length()>0)
					{
						String[] contents=dataDefends.split("\\*");
						for(String content:contents)
						{
							String mtitle=content.split("\\|")[0];
							String mcontent=content.split("\\|")[1];
							defends.put(mtitle, mcontent);
						}
					}
					modelDetail.setRiskdefend(defends);
					modelDetail.setUserInfoId(cursor.getInt(cursor.getColumnIndex("USERINFO_ID")));
					modelDetail.setDate(cursor.getString(cursor.getColumnIndex("DATE")));
					//设置主要参数
					Cursor mainParamCursor=database.rawQuery("select ID,PARAM_NAME,RESULT,COMMONREF," +
							"MODELDETAIL_ID,WARN from MainParam where MODELDETAIL_ID =?",
							new String[]{String.valueOf(cursor.getInt(cursor.getColumnIndex("ID")))});
					List<MainParam> mainParams=null;
					if(mainParamCursor!=null&&mainParamCursor.getCount()>0)
					{
						mainParams=new ArrayList<MainParam>();
						while(mainParamCursor.moveToNext())
						{
							MainParam mainParam=new MainParam();
							mainParam.setId(mainParamCursor.getInt(mainParamCursor.getColumnIndex("ID")));
							mainParam.setParamName(mainParamCursor.getString(mainParamCursor.getColumnIndex("PARAM_NAME")));
							mainParam.setResult(mainParamCursor.getString(mainParamCursor.getColumnIndex("RESULT")));
							mainParam.setModeldetailId(mainParamCursor.getInt(mainParamCursor.getColumnIndex("MODELDETAIL_ID")));
							mainParam.setWarn(mainParamCursor.getString(mainParamCursor.getColumnIndex("WARN")));
							mainParam.setCommonRef(mainParamCursor.getString(mainParamCursor.getColumnIndex("COMMONREF")));
							mainParams.add(mainParam);
						}
						
					}
					modelDetail.setMainParams(mainParams);
					mainParamCursor.close();
					
					//设置评估参数
					Cursor paramCursor=database.rawQuery("select ID,MODEL_NAME,DESCRIPTION,MODEL_ID" +
							" from MODELEVAL where ID =?",
							new String[]{String.valueOf(cursor.getInt(cursor.getColumnIndex("MODELEVAL_ID")))});
					ModelevalModel modelEval=null;
					if(paramCursor!=null&&paramCursor.moveToFirst())
					{
						modelEval=new ModelevalModel();
						modelEval.setId(paramCursor.getInt(paramCursor.getColumnIndex("ID")));
						modelEval.setModelName(paramCursor.getString(paramCursor.getColumnIndex("MODEL_NAME")));
						modelEval.setDescription(paramCursor.getString(paramCursor.getColumnIndex("DESCRIPTION")));
						modelEval.setModelId(paramCursor.getInt(paramCursor.getColumnIndex("MODEL_ID")));
					}
					modelDetail.setModeleval(modelEval);
					paramCursor.close();
					//体检评估详情
					modelDetails.add(modelDetail);
				}
			}
			cursor.close();
		}
		catch(Exception exception)
		{
			exception.printStackTrace();
		}
		return modelDetails;
		
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryAllHealthReportModelFromLocal(int)
	 */
	@Override
	public List<HealthReportModel> queryAllHealthReportModelFromLocal(
			int userinfo_famialy_pk) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryHealthReportByReportIdFromWeb(int)
	 */
	@Override
	public HealthReportModel queryHealthReportByReportIdFromWebAndSaveLocal(
			int health_report_pk) throws Exception {
		
		return null;
	}

	/* (non-Javadoc)
	 * @see net.seehealth.healthpad.business.recordmanage.service.IRecordManageLogic#queryHealthReportByReportIdFromLocal(int)
	 */
	@Override
	public HealthReportModel queryHealthReportByReportIdFromLocal(
			int health_report_pk) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	

}
